By Amin Sabbagh
Student ID: 18055392
EthOS Reference Number: 64001
Intro | Linear Regression Models | Further Insight | Data Preprocessing Intro | Data Preprocessing Continuous | Data Preprocessing Insights
Pandas: Used to extract data from Excel into dataframes
Plotly Express: Used to create interactive data visualizations.
import pandas as pd
import plotly.express as px
# Specify the sheet name from which to read data
file_name = "COL.xlsx"
sheet_name = 'Sheet1'
# Read data from Excel file into a DataFrame
df = pd.read_excel(file_name, sheet_name)
# Save variables
x = df['Date']
y = df['CPI']
# plot the figure
fig = px.line(df, x, y, title='Consumer Inflation Index')
fig.update_traces(line_color='#0000ff')
fig.show()
# Specify the sheet name from which to read data
file_name = "Pies_intro.xlsx"
sheet_name = '1'
# Read data from Excel file into a DataFrame
df_pie_one = pd.read_excel(file_name, sheet_name)
# Define a custom color palette with different shades of blue
custom_palette = ['#0066b2', '#74BBFB']
# Show the plot
fig = px.pie(df_pie_one, names='Compared to a year ago, has your cost of living changed?', values='All Adults',
title='Compared to a year ago, has your cost of living changed?',
labels={'Compared to a year ago, has your cost of living changed?': 'Impact'},
color_discrete_sequence=custom_palette)
fig.show()
# Read data from Excel file into a DataFrame
sheet_name = '2'
df_pie_two = pd.read_excel(file_name, sheet_name)
custom_palette = ['#0066b2', '#74BBFB', '#89CFF0', '#F0F8FF']
# Create a pie chart using Plotly Express
fig = px.pie(df_pie_two, names='Could your household afford to pay an unexpected, but necessary, expense of £850? ',
values='All Adults',
title='Could your household afford to pay an unexpected, but necessary, expense of £850?',
labels={'Could your household afford to pay an unexpected, but necessary, expense of £850? ': 'Impact'},
color_discrete_sequence=custom_palette)
#Explain why 850
# Show the plot
fig.show()
# Read data from Excel file into a DataFrame
sheet_name = '3'
df_pie_three = pd.read_excel(file_name, sheet_name)
custom_palette = ['#0066b2', '#74BBFB', '#89CFF0', '#F0F8FF']
# Create a pie chart using Plotly Express
fig = px.pie(df_pie_three, names='In view of the general economic situation, do you think you will be able to save any money in the next 12 months?',
values='All Adults',
title='Do you think you will be able to save any money in the next 12 months?',
labels={'In view of the general economic situation, do you think you will be able to save any money in the next 12 months?': 'Impact'},
color_discrete_sequence=custom_palette)
# Show the plot
fig.show()
The prevalence of negative responses is concerning on multiple fronts.